<template>
  <div id="navs">
    <div class="w">
      <div class="navs-con">
        <div class="logo">
          <img src="/imges/mi-logo.png" alt="" />
        </div>
        <nav>
          <ul>
            <li
              v-for="(item, i) in navs"
              :key="i"
              @mouseenter="show(item.title)"
              
            >
              {{ item.name }}
            </li>
          </ul>
          <!--  -->
          <div class="list" v-if="list.length" @mouseleave="hide">
            <div class="w">
              <div class="item">
                <top-card
                  v-for="(item, i) in list[0].list"
                  :key="i"
                  :obj="item"
                ></top-card>
              </div>
            </div>
          </div>
        </nav>
        <div class="search">
          <input type="text" placeholder="请输入搜索内容" />
          <button>搜索</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import topCard from "../components/cards/topCard";
export default {
  name: "navs",
  //组件
  components: {
    topCard,
  },
  //数据
  data() {
    return {
      navs: [
        {
          name: "小米手机",
          title: "xiaomi",
        },
        {
          name: "Redmi红米",
          title: "redmi",
        },
        {
          name: "电视",
          title: "tv",
        },
        {
          name: "笔记本",
          title: "book",
        },
        {
          name: "家电",
          title: "jia",
        },
        {
          name: "路由器",
          title: "router",
        },
        {
          name: "智能硬件",
          title: "AI",
        },
        {
          name: "服务",
          title: "weiter",
        },
        {
          name: "社区",
          title: "she",
        },
      ],
      data: [],
      list: [],
    };
  },
  //挂载后
  mounted() {
    this.$http.get("/topgoods.json").then((res) => {
      this.data = res.data.data;
    });
  },
  //方法
  methods: {
    show(i) {
      this.list = this.data.filter((item) => {
        return i == item.title;
      });
    },
    hide(){
        this.list = []
    }
  },
  //过滤，筛选
  filters: {},
  //计算
  computed: {},
  //监听
  watch: {
    //被监听者名称
    $route: {
      //是否一进入页面就开始监听
      immediate: false,
      //执行函数
      handler(newVal, oldVal) {},
      //是否深度监听
      deep: false,
    },
  },
};
</script>

<style lang='scss' scoped>
#navs {
  width: 100%;
  position: relative;
}
.navs-con {
  margin: 20px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  .logo {
    width: 55px;
    height: 50px;
    background-color: #ff6700;
    margin-right: 150px;
  }
  nav {
    width: 80%;
    .list {
      position: absolute;
      width: 100%;
      height: 200px;
      background-color: #fff;
      bottom: -210px;
      left: 0px;
      border-top: 2px solid #eee;
      box-shadow: 0px 4px 4px 2px rgb(226, 226, 226);
      z-index: 1000;
      .item {
        display: flex;
        justify-content: left;
      }
    }
    ul {
      display: flex;
      align-items: center;

      li {
        margin-right: 20px;
        font-size: 17px;
      }
    }
  }
  .search {
    width: 350px;
    position: relative;
    input {
      width: 100%;
      height: 50px;
      text-indent: 1em;
      border: 1px solid #ccc;
    }
    button {
      width: 55px;
      height: 50px;
      border: 1px solid #ccc;
      background-color: #fff;
      position: absolute;
      top: 0px;
      right: 0px;
    }
  }
}
</style>
